var WebSocketServer = require("ws").Server
    , http = require('http')
    , express = require('express')
    , app = express();

app.use(express.static(__dirname + '/public'));

var server = http.createServer(app);
server.listen(8080);

var wss = new WebSocketServer({server: server});

wss.on('connection', function(ws) {

    ws.on('message', function incoming(message, flags) {
        console.info(flags);
        console.log('received: %s', message);
        setTimeout(function timeout() {
            ws.send("Server received " + message);
        }, 500);
    });

    ws.on('close', function() {

    });

});


